package com.example.coreshopapp.task;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.example.coreshopapp.app.Constants;
import com.example.coreshopapp.http.AccessNet;
import com.google.gson.Gson;

import java.util.HashMap;

public class OrderDetailTask {
    private Handler outHandler;
    public void setOutHandler(Handler outHandler) {
        this.outHandler = outHandler;
    }
    private HashMap<String,String> obj;

    public OrderDetailTask(HashMap<String, String> obj) {
        this.obj = obj;
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        //        @SuppressLint("HandlerLeak")
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Message message = outHandler.obtainMessage();
            switch (msg.what) {
                case 9900:
                    message.what = 9900;
                    message.obj = msg.obj;// info;
                    outHandler.sendMessage(message);
                    break;
                case 9901:
                    message.what = 9901;
                    message.obj = msg.obj;// info;
                    Log.d("用户登录50010,", msg.obj.toString() + "");
                    outHandler.sendMessage(message);
                    break;
                case 9902:
                    message.what = 9901;
                    message.obj = "操作异常，请重试";// info;
                    outHandler.sendMessage(message);
                    break;
                case  9904:
                    message.what = 9904;
                    message.obj = msg.obj;// info;
                    outHandler.sendMessage(message);
                    break;
            }
        }
    };

    private boolean freshNetData() {
        new Thread(() -> {
            Gson gson = new Gson();
            boolean re = AccessNet.postDataNet( mHandler, Constants.urlClass.order_detail, 6,gson.toJson(obj)); // 调用接口
        }).start();
        return true;
    }
    public Boolean execute() {
        return freshNetData();
    }
}
